package com.github.prontera.service;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.prontera.domain.SystemAccount;
import com.github.prontera.domain.enums.SystemAccountStatusEnum;
import com.github.prontera.domain.enums.SystemAccountTypeEnum;
import com.github.prontera.persistence.CrudMapper;
import com.github.prontera.persistence.SystemAccountMapper;

/**
 * 系统账户
 */
@Service
public class SystemAccountService extends CrudServiceImpl<SystemAccount>{

	
	@Autowired
	private SystemAccountMapper mapper;
	
	
	@Autowired
    public SystemAccountService(CrudMapper<SystemAccount> mapper) {
        super(mapper);
    }
	
	public int insertAccount(Long clientId,Long productId,Long acceptorId,BigDecimal amount,SystemAccountTypeEnum systemAccountTypeEnum) {
		SystemAccount systemAccount=new SystemAccount();
		systemAccount.setClientId(clientId);
		systemAccount.setAmount(amount);
		systemAccount.setProductId(productId);
		systemAccount.setAcceptorId(acceptorId);
		systemAccount.setType(systemAccountTypeEnum);
		systemAccount.setStatus(SystemAccountStatusEnum.WAITE_ACCEPT);
		return mapper.insert(systemAccount);
	}
	
	public SystemAccount findAccount(Long clientId,Long productId,SystemAccountTypeEnum systemAccountTypeEnum) {
		SystemAccount systemAccount=new SystemAccount();
		systemAccount.setClientId(clientId);
		systemAccount.setProductId(productId);
		systemAccount.setType(systemAccountTypeEnum);
		return findOne(systemAccount);
	}

	public boolean updateAccount(SystemAccount systemAccount) {
		return mapper.updateAccount(systemAccount)>0;
	}

}
